package com.magic.gre.adapter;

import android.content.Context;
import android.view.View;

import com.magic.gre.R;
import com.magic.gre.entity.WordsDetailsBean;
import com.noname.lib_base_java.adapter.CommonAdapter;
import com.noname.lib_base_java.adapter.ViewHolder;

import java.util.List;

/**
 * Author: Lmoumou
 * Date: 2019-01-08 18:28
 * 文件名: LearnFinishAdapter
 * 描述:
 */
public class LearnFinishAdapter extends CommonAdapter<WordsDetailsBean> {

    private OnLearnFinishListener onLearnFinishListener;

    public void setOnLearnFinishListener(OnLearnFinishListener onLearnFinishListener) {
        this.onLearnFinishListener = onLearnFinishListener;
    }

    public LearnFinishAdapter(Context mContext, List<WordsDetailsBean> mData) {
        super(mContext, mData, R.layout.item_learn_finish);
    }

    @Override
    protected void bindData(ViewHolder holder, final int position) {
        WordsDetailsBean bean = mData.get(position);
        holder.setText(R.id.words_tv, bean.getName());
        holder.setText(R.id.content_tv, bean.getMeaning());
        holder.getView(R.id.ripe_words_iv).setSelected(bean.isCooked());
        holder.getView(R.id.new_words_iv).setSelected(bean.isUnirpe());

        holder.getView(R.id.new_words_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onLearnFinishListener!=null){
                    onLearnFinishListener.onNewWords(position);
                }
            }
        });

        holder.getView(R.id.ripe_words_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onLearnFinishListener!=null){
                    onLearnFinishListener.onRipeWords(position);
                }
            }
        });
    }

    public interface OnLearnFinishListener {
        void onNewWords(int position);

        void onRipeWords(int position);
    }
}
